<template>
	<view class="containers">
		<top-back-navbar position="fixed" title="商品详情" :background="pageInfos.navBg"
			:color="pageInfos.navColor"></top-back-navbar>
		<view class="address">
			<view class="address-group box-shadow">
				<view v-if="data.addressid == 0" style="text-align: center;padding: 30upx 0;" @click="addAddr">
					<text style="line-height: 52upx;">添加收货地址</text>
				</view>
				<view v-else style="padding: 30rpx;" @click="open">
					<view class="address-person">
						<view class="address-person-text">{{address.realname}}</view>
						<view class="address-person-text">{{address.mobile}}</view>
						<u-icon name="arrow-right" color="#000000" size="28"></u-icon>
					</view>
					<view class="address-city">{{address.province}}{{address.city}}{{address.area}}</view>
					<view class="address-address">{{address.street}}{{address.address}}</view>
				</view>
			</view>
		</view>
		<view style="padding:0 30rpx;">
			<view class="goods box-shadow" style="background-color: #ffffff;">
				<view class="goods-box-title">订单商品</view>
				<view v-for="(items,i) in res.goods_list" :key="i">
					<view v-for="(item,J) in items.goods" :key="J" style="padding: 30rpx;">
						<view class="webkit">
							<image :src="item.thumb" style="width: 160upx;height: 160upx;margin-right: 24upx;"></image>
							<view class="goods-right-box">
								<view class="goods-right-title">{{item.title}}</view>
								<view class="goods-right-title" v-if="item.optionid != 0">{{item.optiontitle}}</view>
								<view class="goods-right-price">
									<view class="right-price-box">
										<view class="right-price-text">¥{{item.marketprice}}</view>
										<view class="right-price-total">×{{item.total}}</view>
									</view>
									<block v-if="item.kdk > 0">
										<view class="right-price-kdk">
											<view class="right-kdk-text">商品可抵扣积分:{{item.kdk}}</view>
											<view class="right-kdk-text">
												<text>积分抵扣</text>
												<input v-model="item.value"
													style="margin-left: 30upx; border: 1upx solid #999;width: 100upx;text-align: left;padding-left: 10upx;" />
											</view>
										</view>
									</block>
								</view>
								<!-- <view style="font-size: 24upx;color: #C0C0C0;text-decoration: line-through;padding-left: 8upx;font-weight: normal;">&yen;{{item.productprice}}</view> -->
							</view>
						</view>
						<!-- <view style="color:red;text-align: center;font-size: 24upx;margin-top: 20upx;margin-bottom: 16upx;">请选择具体支付方式，默认全部现金支付</view>
						<view style="position: relative;">
							<button type="default" @click="select" :data-id="item.goodsid" style="background: #fff;font-size: 28upx;text-align: left;">{{item.text}}</button>
							<image src="../../../static/select.png" style="width: 32upx;height: 32upx;position: absolute;top: 20upx;right: 20upx;" mode=""></image>
						</view> -->
					</view>
				</view>
			</view>
		</view>
		
		<!-- <view style="background: #fff;padding: 20upx 24upx;">
			<view>共<text style="color: #f55;" v-cloak>{{res.total}}</text>件商品</view>
			<view>需付：</view>
			<view style="text-align: right;font-size: 32upx;color: #f00;">&yen;{{price}}</view>
			<view class="webkit" v-for="(item,index) in cointext" :key="index">
				<view>{{index}}</view>
				<view class="flex" style="text-align: right;color: #666;" v-cloak>{{item}}个</view>
			</view>
		</view>
		<view class="webkit" style="background: #fff;margin-top: 10px;padding: 10px 12px;">
			<view style="width: 150upx;">买家留言</view>
			<textarea placeholder="50字以内(选填)" @blur="textarea" maxlength="50"
				style="font-size: 26upx;padding-top: 10upx;line-height: 40upx;height: 120upx;" />
		</view>

		<view class="content">
			<button type="primary" @click="openType0">开启type=0的actionSheet</button>
			<button type="primary" @click="openType1">开启type=1的actionSheet</button>
			<action ref="action" @itemClick="itemClick" @titleClick="titleClick"></action>
		</view> -->


		<!-- <view class="uni-list">
			<view style="height: 100upx;line-height: 100upx;background-color: #FFFFFF;display: flex;margin: 0 30upx;">
				<text style="flex: 5;">素米最高抵用数量</text>
				<text style="flex: 1;text-align: right;">{{jddk}}</text>
			</view> 
			<radio-group @change="radioChange">

				<!-- <view :style="{display:show_input0}">
					<label class="uni-list-cell uni-list-cell-pd">
						<view v-cloak>{{items[0].name}}</view>
						<view class="val1" v-cloak>- ¥ {{val1}}</view>
						<view>
						    <radio value='0' :checked="current === 0" />
						</view>
					</label>
				</view> -->

		<!-- <view :style="{display:show_input1}">
					<label class="uni-list-cell uni-list-cell-pd">
						<view v-cloak>{{items[1].name}}</view>
						<view class="uni-form-item uni-column" :style="{display:this.show_input1}">
							<input class="uni-input" placeholder="请输入收益抵扣数量" type="text" v-model="tongduibao" @input="input1"/>
						</view>
						<view>
						    <radio value='1' :checked="current === 1" @click="showing_input1" />
						</view>
					</label>
				</view> -->
		<!-- <view :style="{display:show_input2}">
					<label class="uni-list-cell uni-list-cell-pd">
						<view style="width: 200upx;">{{items[2].name}}</view>
						<view class="uni-form-item uni-column" :style="{display:this.show_input2}">
							<input class="uni-input" type="number" placeholder="请输入素米抵扣数量" v-model="jingdou" @input="input2" :style="{display:show_input22}"/>
						</view>
						<view>
						    <radio value='2' :checked="current === 2" @click="showing_input2" />
						</view>
					</label>
				</view> -->
		<!-- <view :style="{display:show_input3}">
					<label class="uni-list-cell uni-list-cell-pd">
						<view v-cloak>{{items[3].name}}</view>
						<view class="uni-form-item uni-column" :style="{display:this.show_input3}">
							<input class="uni-input" type="number" placeholder="请输入素米抵扣数量" v-model="jingdou" @input="input3" :style="{display:show_input33}"/>
						</view>
						<view>
						    <radio value='3' :checked="current === 3" @click="showing_input3" />
						</view>
					</label>
				</view> 

				<label class="uni-list-cell uni-list-cell-pd">
					<view>运费</view>
					<view v-cloak>￥{{data.dispatchprice}}</view>
				</label>
				<label class="uni-list-cell uni-list-cell-pd">
					<view>商品小计</view>
					<view v-cloak>¥{{price}}</view>
				</label>
				<label class="uni-list-cell uni-list-cell-pd">
					<view>我当前剩余积分</view>
					<view v-cloak>{{credit1}}</view>
				</label>

			</radio-group>
		</view>-->
		<!-- <view class="play-type-box">
			<view class="play-type-text">支付方式</view>
			<view class="play-type-choice" @click="isPlayType=!isPlayType">
				<text>{{isPlayType?'余额支付':'微信支付'}}</text>
				<text v-if="isPlayType" class="play-type-text-icon" style="margin: 0 20rpx;">¥</text>
				<u-icon v-if="!isPlayType" name="weixin-circle-fill" color="#c5000b" size="42" style="margin: 0 20rpx;">
				</u-icon>
				<u-icon name="arrow-right" color="#000000" size="28"></u-icon>
			</view>
		</view> -->
		<view style="position: fixed;bottom: 0;width: 100%;height: 100upx;display: flex;z-index: 33;">
			<text
				style="flex: 2; line-height: 100upx;background-color: #fff;padding-left: 30%;font-size: 32rpx;">合计：<text
					style="color:#c5000b">{{price}}</text> 元</text>
			<button @click="submit" style="flex: 2;line-height: 100upx;border-radius: 0;width: 120rpx;"
				:style="{backgroundColor:pageInfos.btnBg,color:pageInfos.btnColor}">立即支付</button>
		</view>
		<!-- 点击地址,右侧打开地址管理选项 -->
		<uni-drawer :visible="rightDrawerVisible" mode="right" @close="closeRightDrawer">
			<view
				style="padding: 110upx 20upx 20upx 20upx;box-sizing: border-box;height: 100%;overflow-y: scroll;overflow-x: hidden;">
				<view v-for="(item,index) in addrlist" :key="index"
					style="border: 1px solid #ccc;border-radius: 10upx;padding: 12upx 20upx;margin-bottom: 20upx;"
					@click="choose" :data-addrid='item.id'>
					<view class="webkit">
						<view class="flex" v-cloak>{{item.realname}}</view>
						<view class="del" @click="del(item.id,item)">删除</view>
					</view>
					<view>{{item.mobile}}</view>
					<view
						style="font-size: 26upx;line-height: 32upx;margin-top: 4upx;padding-top: 12upx;border-top: 2upx dashed #c8c8c8;color: #666;">
						{{item.province}}&nbsp;{{item.city}}&nbsp;{{item.area}}
					</view>
					<view style="font-size: 26upx;line-height: 38upx;color: #666;" v-cloak>
						{{item.street}}&nbsp;&nbsp;{{item.address}}
					</view>
				</view>
				<view class="add_btn" @click="addAddr"
					style="text-align: center;height: 100upx;line-height: 100upx;width: 100%;margin-bottom: 120upx;"
					v-if="addrlist.length <= 4" :style="{backgroundColor:pageInfos.btnBg,color:pageInfos.btnColor}">
					<text style="line-height: 52upx;">新增收货地址</text>
				</view>
			</view>
		</uni-drawer>
		<hfdd-play-model :background="pageInfos.btnBg" :color="pageInfos.btnColor" :orderid="orderid" :playshow="playshow" v-if="playModel == 'ycth'" :close-back="playCloseModel"></hfdd-play-model>
		<play-model :background="pageInfos.btnBg" :color="pageInfos.btnColor" :orderid="orderid" :playshow="playshow" v-if="playModel != 'ycth'" :close-back="playCloseModel"></play-model>
	</view>
</template>

<script>
	import uniDrawer from '../../../components/uni-drawer.vue';
	import playModel from '../pay/pay.vue';
	import hfddPlayModel from '../pay/hfddPay.vue';
	import action from "../../../components/shufei-action/action.vue"
	export default {
		components: {
			uniDrawer,
			action,
			playModel,
			hfddPlayModel
		},
		data() {
			return {
				val1: '',
				orderid: '',
				isPlayType: false,
				playshow: false,
				tongduibao: 0,
				jingdou: 0,
				show_input0: 'block',
				show_input1: 'block',
				show_input2: 'block',
				show_input3: 'block',
				show_input22: 'none',
				show_input33: 'none',
				rightDrawerVisible: false,
				res: [],
				openid: '',
				data: [],
				address: [],
				addrlist: [],
				subcoin: [],
				coin: [],
				cointext: {},
				// 需要支付价格
				price: '',
				price_base: 0,
				numvalue: 0,
				items: [{
					value: '0',
					name: '收益全部抵扣'
				}, {
					value: '1',
					name: '收益加现金'
				}, {
					value: '2',
					name: '素米抵用'
				}, {
					value: '3',
					name: '素米加收益'
				}],
				current: 5,
				jddk: 0,
				tdb: 0,
				a_kzp: 0,
				credit1: 0,
				a_kzp_base: 0,
				jddk_base: 0,
				id: '',
				fromcart: '',
				carrierid: '',
				addressid: '',
				remark: '',
				fromquick: '',
				dispatchprice: '',
				zzzf: '',
				sjzzzf: '',
				iid: '',
				optionid: '',
				total: '',
				goodsid: '',
				zzff: '',
				pageInfos: {},
				playModel:''
			};
		},
		onLoad: function(e) {
			this.playModel=e.playModel;
			this.pageInfos=this.$GetPageInfo(e.type)
			uni.showLoading()
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
					if (e.id == undefined) {
						this.setAjax()
					} else {
						this.setBuyAjax(e)
						this.goodsid = e.id
						this.iid = e.id
						this.optionid = e.optionid
						this.total = e.total
					}
				},
				fail: () => {
					uni.navigateBack()
				}
			});
		},
		methods: {
			playCloseModel(){
				this.playshow=false;
			},
			openType0() {
				this.$refs.action.actionConfig = {
					title: '您的账户最多可抵扣' + this.jddk,
					// jingdou: this.jingdou,
					jddk: this.jddk,

					// summary:'请选择取消订单原因',
					// list:['我不想买了','信息填写错误，重新拍','其他原因'],
					type: 0,
					isBorderColor: false,
					specClass: 'show',
				}
			},
			// openType1(){
			// 	this.$refs.action.actionConfig={
			// 			title:'退款',
			// 			summary:'订单支付已超过30分钟原则上不能退款，如有疑问请联系客服',
			// 			type:1,
			// 			cancelColor:"#FF3D45",
			// 			isBorderColor:true,
			// 			specClass: 'show',
			// 	}
			// },
			// itemClick(index,type){
			// 		//这里根据不同的类型点击的索引值,做对应的逻辑处理
			// 		console.log(`你点击的action-sheet的类型是${type},list对应的索引值是${index}`)
			// },
			// titleClick(type){
			// 		//这里根据不同的类型做对应的逻辑处理
			// 		console.log(type)
			// },
			jingdouInput(e) {
				this.jingdou = e.target.value
				console.log(this.jingdou)
				console.log(this.jddk)
				// 输入的大于可以抵扣的
				// setTimeout(()=>{
				if (this.jingdou > this.jddk) {
					this.jingdou = this.jddk
					return
				}
				// },20)
				console.log(this.jingdou)
			},
			setBuyAjax(value) {
				// console.log(value)
				uni.request({
					url: this.$BASE_URL + '/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=order.create&app=1',
					method: 'POST',
					data: {
						openid: this.openid,
						id: value.id,
						optionid: value.optionid,
						total: value.total,
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					success: res => {
						console.log(res)
						uni.hideLoading()
						for (var i in res.data.goods_list) {
							// console.log(i)
							for (var j in res.data.goods_list[i].goods) {
								res.data.goods_list[i].goods[j].text = '¥' + res.data.goods_list[i].goods[j]
									.ggprice
							}
						}
						this.jddk = res.data.jfdk
						this.jddk_base = this.jddk
						this.tdb = res.data.tdb
						this.a_kzp = res.data.member.a_kzp
						this.a_kzp_base = this.a_kzp
						this.credit1 = res.data.member.credit1
						this.price = res.data.realprice
						this.price_base = this.price

						this.res = res.data
						this.address = res.data.address

						if (this.a_kzp < this.price) {
							this.show_input0 = 'none'
						}
						// 没有通配宝
						if (this.a_kzp == '' || this.a_kzp == 0 || this.a_kzp == null) {
							this.show_input0 = 'none'
							this.show_input1 = 'none'
						}
						// 没有京豆
						if (this.jddk == '' || this.jddk == 0 || this.jddk == null) {
							this.show_input2 = 'none'
							this.show_input3 = 'none'
						}

						var dispatchprice = '';
						if (res.data.exchangeOrder != '') {
							dispatchprice = res.data.exchangepostage
						} else if (res.data.taskgoodsprice != null && res.data.taskgoodsprice != 0 && res.data
							.taskgoodsprice != '' && res.data.taskgoodsprice != null) {
							dispatchprice = res.data.taskgoodsprice
						} else {
							dispatchprice = res.data.dispatch_price
						}
						var price = 0
						for (var i in res.data.goods) {
							price = price + Number(res.data.goods[i].ggprice)
						}
						var zzzf = '0:' + price


						var sData = '{"id":' + res.data.createInfo.id + ',"fromcart":' + res.data.createInfo
							.fromcart + ',"carrierid":' + res.data.createInfo.storeid + ',"addressid":"' + res
							.data.createInfo.addressid + '","remark":"","fromquick":' + res.data.createInfo
							.fromquick + ',"dispatchprice":' + dispatchprice + ',"zzzf":"' + zzzf +
							'","sjzzzf":"' + res.data.zsjzzzf + '","openid":"' + this.openid + '"'
						for (var i in res.data.createInfo.goods) {
							for (var j in res.data.createInfo.goods[i]) {
								sData += ',"goods[' + i + '][' + j + ']":"' + res.data.createInfo.goods[i][j] +
									'"'
							}
						}

						sData += '}'
						var data = JSON.parse(sData)
						this.data = data

						var coinid = []
						var sjzzzf = ''
						for (var i in this.res.goods_list) {
							for (var j in this.res.goods_list[i].goods) {
								var asd = []
								var g = this.res.goods_list[i].goods[j]
								asd.txt = '￥' + g.ggprice
								asd.id = '0'
								asd.num = 0
								asd.price = Number(g.ggprice)
								asd.shopid = i
								asd.goodsid = g.goodsid
								asd.coinname = ''
								coinid.push(asd)
							}
						}
						this.subcoin = coinid
					},
					fail: () => {},
					complete: () => {}
				});
			},
			setAjax() {
				uni.request({
					url: this.$BASE_URL + '/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=order.create&app=1',
					method: 'POST',
					data: {
						'openid': this.openid
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					success: res => {
						if (this.a_kzp < this.price) {
							this.show_input0 = 'none'
						}
						// 没有通配宝
						if (this.a_kzp == '' || this.a_kzp == 0) {
							this.show_input0 = 'none'
							this.show_input1 = 'none'
						}
						// 没有京豆
						if (this.jddk == '' || this.jddk == 0) {
							this.show_input2 = 'none'
							this.show_input3 = 'none'
						}

						uni.hideLoading()
						for (var i in res.data.goods_list) {
							for (var j in res.data.goods_list[i].goods) {
								res.data.goods_list[i].goods[j].text = '¥' + res.data.goods_list[i].goods[j]
									.ggprice
							}
						}
						this.price = res.data.goodsprice
						this.res = res.data
						this.address = res.data.address
						var new_arr = []
						for (var x = 0; x < this.res.goods_list.length; x++) {
							new_arr.push(this.res.goods_list[x].goods)
						}
						// console.log(new_arr)
						var new_arr1 = []
						var obj = []
						var arr = []
						for (var x = 0; x < new_arr.length; x++) {
							// console.log(new_arr[x])
							for (var y = 0; y < new_arr[x].length; y++) {
								// console.log(new_arr[x][y].value)
								arr[y] = new_arr[x][y].goodsid + ':' + new_arr[x][y].value
								new_arr1.push(arr[y])
							}
						}
						// console.log(new_arr1)
						for (var x = 0; x < new_arr1.length; x++) {
							// console.log(new_arr1[x])
							var zfff = new_arr1.join(",");
						}
						this.zzzf = zfff
						var dispatchprice = '';
						if (res.data.exchangeOrder != '') {
							dispatchprice = res.data.exchangepostage
						} else if (res.data.taskgoodsprice != null && res.data.taskgoodsprice != 0 && res.data
							.taskgoodsprice != '' && res.data.taskgoodsprice != null) {
							dispatchprice = res.data.taskgoodsprice
						} else {
							dispatchprice = res.data.dispatch_price
						}
						var price = 0
						for (var i in res.data.goods) {
							price = price + Number(res.data.goods[i].ggprice)
						}
						// var zzzf = '0:'+ price


						var sData = '{"id":' + res.data.createInfo.id + ',"fromcart":' + res.data.createInfo
							.fromcart + ',"carrierid":' + res.data.createInfo.storeid + ',"addressid":"' + res
							.data.createInfo.addressid + '","remark":"","dispatchprice":' + dispatchprice +
							',"zzzf":"' + this.zzzf + '","sjzzzf":"' + res.data.zsjzzzf + '","openid":"' + this
							.openid + '"'
						for (var i in res.data.createInfo.goods) {
							for (var j in res.data.createInfo.goods[i]) {
								sData += ',"goods[' + i + '][' + j + ']":"' + res.data.createInfo.goods[i][j] +
									'"'
							}
						}
						sData += '}'
						var data = JSON.parse(sData)
						this.data = data
						this.id = res.data.createInfo.id
						this.fromcart = res.data.createInfo.fromcart
						this.carrierid = res.data.createInfo.storeid
						this.addressid = res.data.createInfo.addressid
						this.remark = ''
						// this.fromquick = fromquick
						this.dispatchprice = dispatchprice
						// this.zzzf = zzzf
						this.sjzzzf = res.data.zsjzzzf
						console.log(res.data)
						// 这里我修改了i为0,因为暂时未遇到有i= 1 的情况
						this.goods_list = res.data.goods_list[0].goods[j]

						var coinid = []
						var sjzzzf = ''
						for (var i in this.res.goods_list) {
							for (var j in this.res.goods_list[i].goods) {
								var asd = []
								var g = this.res.goods_list[i].goods[j]
								asd.txt = '￥' + g.ggprice
								asd.id = '0'
								asd.num = 0
								asd.price = Number(g.ggprice)
								asd.shopid = i
								asd.goodsid = g.goodsid
								asd.coinname = ''
								coinid.push(asd)
							}
						}
						this.subcoin = coinid
					},
					fail: () => {},
					complete: () => {}
				});
			},
			show_close() {
				this.show = true
			},
			close() {
				this.show = false
			},
			textarea(e) {
				this.data.remark = e.detail.value
			},
			addAddr() {
				uni.navigateTo({
					url: '../../member/address/post?goodsid=' + this.goodsid + '&optionid=' + this.optionid +
						'&total=' + this.total
				});
			},
			open() {
				uni.request({
					url: this.$BASE_URL + '/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=member.address&app=1',
					method: 'POST',
					data: {
						'openid': this.openid
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					success: res => {
						uni.hideLoading()
						this.addrlist = res.data
						// console.log(this.addrlist)
					},
					fail: () => {},
					complete: () => {}
				});
				this.rightDrawerVisible = !this.rightDrawerVisible
			},
			choose(e) {
				if (this.data.addressid != e.currentTarget.dataset.addrid) {
					uni.showLoading();
					this.data.addressid = e.currentTarget.dataset.addrid
					uni.request({
						url: this.$BASE_URL +
							'/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=member.address.post&app=1&id=' +
							e.currentTarget.dataset.addrid,
						method: 'POST',
						data: {
							'openid': this.openid
						},
						header: {
							'Content-Type': 'application/x-www-form-urlencoded'
						},
						success: res => {
							uni.hideLoading()
							this.address = res.data
							console.log(this.address)
							this.closeRightDrawer()
						},
						fail: () => {},
						complete: () => {}
					});
				} else {
					this.closeRightDrawer()
				}
			},
			select(e) {
				for (var i in this.res.goods_list) {
					for (var j in this.res.goods_list[i].goods) {
						var g = this.res.goods_list[i].goods[j]
						if (g.goodsid == e.currentTarget.dataset.id) {
							var coinlist = [],
								coinid = [],
								asd = [];
							coinlist.push('￥' + g.ggprice)
							asd.txt = '￥' + g.ggprice
							asd.id = '0'
							asd.num = 0
							asd.price = Number(g.ggprice)
							asd.shopid = i
							asd.goodsid = g.goodsid
							asd.coinname = ''
							coinid.push(asd)
							for (var k in g.coin) {
								var l = '￥' + g.xjsl + ' + ' + g.coin[k].number + '个' + g.coin[k].coinname
								var cn = g.coin[k].number + '个' + g.coin[k].coinname
								coinlist.push(l)
								var a = []
								a.txt = l
								a.coinname = g.coin[k].coinname
								a.id = g.coin[k].id
								a.num = g.coin[k].number
								a.price = g.xjsl
								a.goodsid = g.goodsid
								a.shopid = i
								coinid.push(a)
							}
							uni.showActionSheet({
								itemList: coinlist,
								success: (e) => {
									for (var i in this.subcoin) {
										if (this.subcoin[i].goodsid == coinid[e.tapIndex].goodsid) {
											this.subcoin[i].id = coinid[e.tapIndex].id
											this.subcoin[i].num = coinid[e.tapIndex].num
											this.subcoin[i].price = coinid[e.tapIndex].price
											this.subcoin[i].txt = coinid[e.tapIndex].txt
											this.subcoin[i].coinname = coinid[e.tapIndex].coinname
										}
									}
									for (var i in this.res.goods_list) {
										for (var j in this.res.goods_list[i].goods) {
											if (this.res.goods_list[i].goods[j].goodsid == coinid[e.tapIndex]
												.goodsid) {
												this.res.goods_list[i].goods[j].text = coinid[e.tapIndex].txt
											}
										}
									}
									var ary = {},
										p = 0
									for (var i in this.subcoin) {
										if (this.subcoin[i].id != 0) {
											if (ary[this.subcoin[i].coinname] == undefined) {
												ary[this.subcoin[i].coinname] = this.subcoin[i].num
											} else {
												ary[this.subcoin[i].coinname] += this.subcoin[i].num
											}
										}
										p += this.subcoin[i].price
									}
									this.cointext = ary
									this.price = p
								}
							})
						}
					}
				}
			},
			submit() {
				console.log(1);
				if (this.orderid) {
					this.playshow = true;
					return;
				}
				var new_arr = []
				for (var x = 0; x < this.res.goods_list.length; x++) {
					new_arr.push(this.res.goods_list[x].goods)
				}
				// console.log(new_arr)
				var new_arr1 = []
				var new_arr2 = []
				var new_arr3 = []
				var obj = []
				var arr = []
				var kdk = []
				for (var x = 0; x < new_arr.length; x++) {
					console.log(new_arr[x])
					for (var y = 0; y < new_arr[x].length; y++) {
						// console.log(new_arr[x][y].value)
						obj[y] = new_arr[x][y].value
						kdk[y] = new_arr[x][y].kdk
						arr[y] = new_arr[x][y].goodsid + ':' + new_arr[x][y].value
						new_arr1.push(arr[y])
						new_arr2.push(obj[y])
						new_arr3.push(kdk[y])
					}
				}
				console.log(new_arr3)
				for (var x = 0; x < new_arr1.length; x++) {
					// console.log(new_arr1[x])
					var zfff = new_arr1.join(",");
				}
				this.zzzf = zfff
				var add = 0
				for (var y = 0; y < new_arr2.length; y++) {
					// console.log(new_arr2[y])
					add += Number(new_arr2[y])
				}
				// console.log(add)
				var kdkje = 0
				for (var y = 0; y < new_arr3.length; y++) {
					// console.log(new_arr3[y])
					kdkje += Number(new_arr3[y])
				}
				for (var i = 0, length = new_arr2.length; i < length; i++) {
					// console.log(new_arr2[i])
					// console.log(new_arr3[i])
					if (new_arr2[i] > new_arr3[i]) {
						uni.showToast({
							title: '输入的积分值超出商品可抵扣积分范围',
							icon: 'none'
						})
						return
					}
				}
				uni.request({
					url: this.$BASE_URL + '/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=order.create&app=1',
					method: 'POST',
					data: {
						openid: this.openid,
						id: this.iid,
						optionid: this.optionid,
						total: this.total,
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					success: res => {
						console.log(res)
						uni.hideLoading()
						for (var i in res.data.goods_list) {
							// console.log(i)
							for (var j in res.data.goods_list[i].goods) {
								res.data.goods_list[i].goods[j].text = '¥' + res.data.goods_list[i].goods[j]
									.ggprice
							}
						}
						// this.price = res.data.goodsprice
						this.res = res.data
						this.address = res.data.address
						var dispatchprice = '';
						if (res.data.exchangeOrder != '') {
							dispatchprice = res.data.exchangepostage
						} else if (res.data.taskgoodsprice != null && res.data.taskgoodsprice != 0 && res.data
							.taskgoodsprice != '' && res.data.taskgoodsprice != null) {
							dispatchprice = res.data.taskgoodsprice
						} else {
							dispatchprice = res.data.dispatch_price
						}
						var price = 0
						for (var i in res.data.goods) {
							price = price + Number(res.data.goods[i].ggprice)
						}
						var zzzf = '0:' + price

						if (this.jingdou == "" || this.jingdou == undefined) {
							this.jingdou = 0
						}
						if (this.tongduibao == "" || this.tongduibao == undefined) {
							this.tongduibao = 0
						}
						var sData = '{"id":' + res.data.createInfo.id + ',"fromcart":' + res.data.createInfo
							.fromcart + ',"carrierid":' + res.data.createInfo.storeid + ',"addressid":"' + res
							.data.createInfo.addressid + '","remark":"","dispatchprice":' + dispatchprice +
							',"zzzf":"' + this.zzzf + '","sjzzzf":"' + res.data.zsjzzzf + '","openid":"' + this
							.openid + '","tongduibao":' + this.tongduibao + ',"jindou":' + this.jingdou +
							',"istongduibao":' + this.numvalue
						for (var i in res.data.createInfo.goods) {
							for (var j in res.data.createInfo.goods[i]) {
								sData += ',"goods[' + i + '][' + j + ']":"' + res.data.createInfo.goods[i][j] +
									'"'
							}
						}
						sData += '}'
						var data = JSON.parse(sData)
						this.data = data
						// console.log(this.data)

						this.id = res.data.createInfo.id
						this.fromcart = res.data.createInfo.fromcart
						this.carrierid = res.data.createInfo.storeid
						this.addressid = res.data.createInfo.addressid
						this.remark = ''
						// this.fromquick = fromquick	
						this.dispatchprice = dispatchprice
						// this.zzzf = this.zzzf
						this.sjzzzf = res.data.zsjzzzf
						// 这里我修改了i为0,因为暂时未遇到有i= 1 的情况
						this.goods_list = res.data.goods_list[0].goods[j]

						var coinid = []
						var sjzzzf = ''
						for (var i in this.res.goods_list) {
							for (var j in this.res.goods_list[i].goods) {
								var asd = []
								var g = this.res.goods_list[i].goods[j]
								asd.txt = '￥' + g.ggprice
								asd.id = '0'
								asd.num = 0
								asd.price = Number(g.ggprice)
								asd.shopid = i
								asd.goodsid = g.goodsid
								asd.coinname = ''
								coinid.push(asd)
							}
						}
						this.subcoin = coinid
						uni.request({
							url: this.$BASE_URL +
								'/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=order.create.submit&app=1',
							method: 'POST',
							data: this.data,
							header: {
								'Content-Type': 'application/x-www-form-urlencoded'
							},
							success: res => {
								console.log(res)
								if (res.data.status == 1) {
									// uni.navigateTo({
									// 	url: '../pay/pay?id=' + res.data.result.orderid
									// });
									this.orderid = res.data.result.orderid;
									this.playshow = true;
								} else {
									uni.showToast({
										title: res.data.result.message.toString(),
										icon: "none"
									});
								}
							},
							fail: () => {},
							complete: () => {}
						});
					},
					fail: () => {},
					complete: () => {}
				});

			},
			closeRightDrawer() {
				this.rightDrawerVisible = false;
			},
			showRightDrawer() {
				this.rightDrawerVisible = true;
			},
			del(e, item) {
				// 删除
				console.log(item)
				// if()
				uni.request({
					url: this.$BASE_URL +
						'/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=member.address.delete&app=1',
					method: 'POST',
					data: {
						'openid': this.openid,
						'id': e
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					success: res => {
						uni.hideLoading()
						console.log(e)
						setTimeout(() => {
							uni.redirectTo({
								url: '../create/create?id=' + this.goodsid + '&optionid=' +
									this.optionid + '&total=' + this.total
							});
						}, 500)
					},
					fail: () => {},
					complete: () => {}
				})

			},
			// 按钮改变时
			radioChange(evt) {
				for (let i = 0; i < this.items.length; i++) {
					if (this.items[i].value === evt.target.value) {
						this.current = i;
						// 全部使用收益
						if (this.current == 0) {
							this.numvalue = 1
							this.tongduibao = 0
							this.jingdou = 0
							this.jddk = this.jddk_base
							this.a_kzp = this.a_kzp_base
							this.price = this.price_base
							// 收益小于price
							if (this.tdb < this.price) {
								this.val1 = this.tdb
							} else {
								// 收益大于price
								this.val1 = this.price
							}
							// 收益剩余
							this.a_kzp = this.a_kzp - this.val1
							// 支付0
							this.price = this.price - this.val1
						}
						// 收益加现金
						if (this.current == 1) {
							this.numvalue = 2
							this.price = this.price_base
							this.tongduibao = 0
							this.jingdou = 0
						}
						// 素米抵用
						if (this.current == 2) {
							this.numvalue = 3
							this.price = this.price_base
							this.jingdou = 0
							this.show_input22 = 'block'
							this.show_input33 = 'none'
						}
						// 素米加收益
						if (this.current == 3) {
							this.numvalue = 4
							this.price = this.price_base
							this.jingdou = 0
							this.show_input22 = 'none'
							this.show_input33 = 'block'
						}
						break;
					}
				}
			},
			showing_input1() {
				this.show_input1 = 'block'
			},
			showing_input2() {
				this.show_input2 = 'block'
			},
			showing_input3() {
				this.show_input3 = 'block'
			},
			// 收益加现金
			input1() {
				setTimeout(() => {
					this.jddk = this.jddk_base
					this.a_kzp = this.a_kzp_base
					this.price = this.price - this.tongduibao

					// 如果总收益数量大于price
					if (this.a_kzp > this.price) {
						// 输入了收益
						if (this.tongduibao) {
							// 输入收益小于价格
							if (this.tongduibao < this.price_base) {
								// 重置
								this.price = this.price_base
								this.price = this.price - this.tongduibao
							}
							// 输入收益大于价格
							else {
								uni.showToast({
									title: '收益要不到那么多哦~',
									icon: "none",
								});
								setTimeout(() => {
									this.price = this.price_base
									this.tongduibao = this.price_base
									this.price = this.price - this.tongduibao
								}, 200)
							}
						} else {
							// 没有输入收益
							uni.showToast({
								title: '请输入收益抵扣数量',
								icon: "none",
								success: () => {
									this.price = this.price_base
								}
							});
						}
					}
					// 如果总收益小于price
					else {
						if (this.tongduibao) {
							// 总收益小于输入的
							if (this.a_kzp < this.tongduibao) {
								// 将输入的收益数改为总的收益数
								this.tongduibao = this.a_kzp
								this.price = this.price - this.tongduibao
								return
							} else {
								// 总收益大于输入的
								this.price = this.price - this.tongduibao
							}
						} else {
							// 没有输入收益
							uni.showToast({
								title: '请输入收益抵扣数量',
								icon: "none",
								success: function() {
									this.price = this.price_base
								}
							});
						}
					}
				}, 20)

			},
			input2(e) {
				this.jingdou = e.target.value
				this.price = this.price_base
				console.log(this.jddk_base)
				setTimeout(() => {
					this.jddk = this.jddk_base
					this.a_kzp = this.a_kzp_base
					// 输入素米数大于总素米数量
					// 后台的素米抵扣已经判断过不会大于price
					if (this.jddk < this.jingdou) {
						this.price = this.price_base
						this.jingdou = this.jddk
						this.price = this.price - this.jddk
						// return
					} else if (this.jingdou == '' || this.jingdou == undefined) {
						this.price = this.price_base
						// this.current = 0  // 修改选顶的按钮
					} else {
						// 需支付的金额
						this.price = this.price - this.jingdou;
						this.price = this.price.toFixed(2).toString();
						console.log(this.price)
					}

				}, 20)

			},
			input3() {
				setTimeout(() => {
					this.jddk = this.jddk_base
					this.a_kzp = this.a_kzp_base
					//如果填写的素米数量大于可抵扣的素米数量
					if (this.jingdou > this.jddk) {
						uni.showToast({
							title: '最多抵扣' + this.jddk + '素米',
							icon: "none"
						});
						this.jingdou = this.jddk
						return
					}
					// 输入小于总素米
					else {
						this.price = this.price_base
						// 去除素米剩余price
						this.price = this.price - this.jingdou;
						this.price.toString();
						// 收益小于price
						// if (this.tdb < this.price) {
						// 	this.price = this.price - this.tdb
						// 	// 收益剩余
						// 	// this.a_kzp = this.a_kzp - this.tdb
						// } else {
						// 	// 收益大于price
						// 	this.val1 = this.price
						// }
					}
				}, 20)

			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100vh;
		background-color: #F4F6FA;
	}
	.containers{
		position: absolute;
		top:0;
		left:0;
		width:100%;
		height:100%;
		overflow: hidden;
	}
	.val1 {
		margin-left: 280upx;
	}

	.uni-input {
		width: 350upx;
		margin-left: 100upx;
	}

	.goods_mount {
		padding-left: 30upx;
		background-color: #fff;
	}

	.uni-list {
		margin: 20upx 0 120upx 0;
	}

	.address {
		position: relative;
		padding: 30rpx;
	}

	.address-group {
		border-radius: 18rpx;
		background-color: #fff;
		position: relative;
		.address-person {
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		.address-person-text {
			font-size: 30rpx;
			font-weight: 550;
		}

		.address-city {
			margin-top: 20rpx;
			font-size: 28rpx;
			color: #7f7f80;
		}

		.address-address {
			font-size: 28rpx;
			color: #7f7f80;
		}
	}
	
	.goods{
		border-radius: 20rpx;
	}
	.goods-box-title{
		height: 90rpx;
		line-height: 90rpx;
		font-size: 30rpx;
		font-weight: 600;
		padding:0 30rpx;
	}
	.goods-right-box {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		flex: 1;

		.goods-right-title {
			padding: 10rpx 0;
			font-weight: bold;
		}
	}

	.goods-right-price {
		width: 100%;

		.right-price-box {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.right-price-text {
				font-size: 30rpx;
				color: #c5000b;
			}

			.right-price-total {
				font-size: 30rpx;
			}
		}

		.right-price-kdk {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 10rpx 0;

			.right-kdk-text {
				display: flex;
				align-items: center;
				font-size: 28rpx;
				color: #888;
			}
		}
	}

	.play-type-box {
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #ffffff;
		padding: 30rpx;

		.play-type-text {
			font-size: 30rpx;
			font-weight: bold;
		}

		.play-type-text-icon {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 40rpx;
			height: 40rpx;
			font-size: 30rpx;
			color: #fff;
			border-radius: 50%;
			background-color: #c5000b;
		}

		.play-type-choice {
			display: flex;
			align-items: center;
			font-size: 30rpx;
		}
	}

	// .address:after {
	// 	content: ' ';
	// 	position: absolute;
	// 	left: 0;
	// 	width: 100%;
	// 	height: 6upx;
	// 	background: url(../../../static/order_line.png) repeat-x;
	// }

	// .address:before {
	// 	content: " ";
	// 	display: inline-block;
	// 	-webkit-transform: rotate(45deg);
	// 	-ms-transform: rotate(45deg);
	// 	transform: rotate(45deg);
	// 	height: 16upx;
	// 	width: 16upx;
	// 	border-width: 2upx 2upx 0 0;
	// 	border-color: #b2b2b2;
	// 	border-style: solid;
	// 	position: absolute;
	// 	top: 50%;
	// 	margin-top: -10upx;
	// 	right: 30upx;
	// }

	.del {
		color: #888;
	}
	.play-template-model .u-drawer{
		height: 100vh!important;
		top:unset!important;
	}
</style>
